<h1 class="crayons-title mb-3">Privileged Reactions</h1>

<div class="mb-6">
  <%= search_form_for @q, url: admin_privileged_reactions_path, class: "inline-flex" do |f| %>
    <%= f.search_field :user_username_cont, aria: { label: "Search" }, placeholder: "User", class: "crayons-textfield" %>
    <%= f.select(
          :category_eq,
          options_for_select(["", [t("views.reactions.category.thumbsup"), "thumbsup"], [t("views.reactions.category.thumbsdown"), "thumbsdown"], [t("views.reactions.category.vomit"), "vomit"]], @q.category_eq),
          {},
          class: "crayons-select mx-3",
          aria: { label: "Action" },
        ) %>
    <%= f.submit "Search", class: "crayons-btn" %>
  <% end %>
</div>

<%= paginate @privileged_reactions %>

<table class="crayons-table" width="100%">
  <thead>
    <tr>
      <th scope="col">ID</th>
      <th scope="col">User</th>
      <th scope="col">Type</th>
      <th scope="col">Action</th>
      <th scope="col">Content</th>
      <th scope="col">Date</th>
    </tr>
  </thead>
  <tbody class="crayons-card">
    <% @privileged_reactions.select(&:reactable).each do |reaction| %>
      <tr>
        <td class="whitespace-nowrap"><%= reaction.id %></td>
        <td><%= link_to reaction.user.username, admin_user_path(reaction.user_id) %></td>
        <td class="whitespace-nowrap"><%= reaction.reactable_type %></td>
        <td><%= t("views.reactions.category.#{reaction.category}") %></td>
        <td>
          <% if reaction.reactable_type == "Article" %>
            <%= link_to reaction.reactable.title, reaction.reactable.path %>
          <% elsif reaction.reactable_type == "User" %>
            <%= link_to reaction.reactable.username, reaction.reactable.path %>
          <% elsif reaction.reactable_type == "Comment" %>
            <%= link_to "#{reaction.reactable.user.username}'s Comment", reaction.reactable.path %>
          <% end %>
        </td>
        <td><%= reaction.created_at %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<%= paginate @privileged_reactions %>
